// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ServerMixin from './mixin/ServerMixin'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import '@/style/common.less'
import {
    getUserInfo,
    logout
} from '@/utils/auth'
import utils from '@/utils'

Vue.config.productionTip = false

/* eslint-disable no-new */
Vue.use(ServerMixin);
Vue.use(ElementUI);


// // 拦截白名单
const whiteList = ['/login', '/home'];

router.beforeEach((to, from, next) => {
    // console.log(to.path)
    if (whiteList.indexOf(to.path) != -1) {

        next()
    } else {

        const userInfo = getUserInfo()
        if (userInfo) {
            next();
        } else {
            const token = utils.getQueryString('token');
            if (utils.isNotEmpty(token)) {
                // store.dispatch("login", {
                //     token: token,
                //     callback(res) {
                next();
                //     }
                // });

            } else {
                // console.log('1aaaaaaaaaaaaaaa')
                alert('请登录')
                router.push({ path: '/login' })
                next();

            }
        }
    }
});





new Vue({
    el: '#app',
    router,
    components: {
        App
    },
    template: '<App/>'
})